package com.sky.controller;


import com.sky.dto.DishPageListDto;
import com.sky.dto.addAndUpdateDishDto;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author gcl
 * @since 2024-06-25
 */
@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private IDishService dishService;

    @GetMapping("/page")
    public Result getDishPageList(DishPageListDto dto) {
        PageResult dishes = dishService.getDishPageList(dto);
        return Result.success(dishes);
    }

    @PostMapping
    public Result addDish(@RequestBody addAndUpdateDishDto dto) {
        dishService.addDish(dto);
        return Result.success();
    }

    @PutMapping
    public Result updateDish(@RequestBody addAndUpdateDishDto dto) {
        dishService.updateDish(dto);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteDish(@RequestParam("ids") List<Long> ids) {
        dishService.deleteDish(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getDishById(@PathVariable Long id) {
        DishVO dishVO = dishService.getDishById(id);
       return Result.success(dishVO);
    }

    @PostMapping("/status/{status}")
    public Result updateDishStatus(@PathVariable Integer status,  Long id) {
        dishService.updateDishStatus(status,id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getDishList(Long categoryId) {
        List<Dish> dishList = dishService.getDishList(categoryId);
        return Result.success(dishList);
    }
}
